<template>
  <div>
    <el-card class="box-card" style="height:800px">
      <div slot="header" class="clearfix">
        <span>
          <navigation />
        </span>
      </div>
      <el-scrollbar class="page-component__scroll" style="height:100%">
        <div style="height:670px;">
          <el-table :data="tableData" border :header-cell-style="{background:'#f5f5f5'}" height="650px">
            <el-table-column align="center" prop="createDate" label="操作日期"></el-table-column>
            <el-table-column align="center" prop="username" label="用户名"></el-table-column>
            <el-table-column align="center" prop="ip" label="ip地址"></el-table-column>
            <el-table-column align="center" prop="operation" label="操作"></el-table-column>
          </el-table>
        </div>
      </el-scrollbar>
      <el-pagination
        style="float:right"
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :current-page="currentPage"
        :total="total"
        @current-change="handleCurrentChange"
      ></el-pagination>
    </el-card>
  </div>
</template>
<script>
export default {
  data() {
    return {
      tableData: [],
      pageSize: 14,
      currentPage: 1,
      total: 0,
    };
  },
  mounted() {
    this.getLoginInfo();
  },
  methods: {
    getLoginInfo() {
      this.$axios
        .post("log/getListByPage/" + this.currentPage + "/" + this.pageSize)
        .then((res) => {
          if (res.code == 200) {
            for (let i = 0; i < res.data.list.length; i++) {
              res.data.list[i].createDate = this.time(
                res.data.list[i].createDate
              );
            }
            this.tableData = res.data.list;
            this.total = res.data.total;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    time(time = +new Date()) {
      var date = new Date(time); // 增加8小时
      return date.toJSON().substr(0, 19).replace("T", " ");
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getLoginInfo();
    },
  },
};
</script>
<style scoped>
</style>